<?php
namespace app\port\controller;
use app\common\controller\Base;
use jwt\Jwt;
class Common extends Base{
    function __construct(){
        parent::__construct();
        $token=input('token');
        $user=[];
        // 验证token
        if($token){
            $check=Jwt::decode($token);
            if($check['success']){
                $data=$check['data']; //[id,_loginTime]
                if(!isset($data['id'])||!isset($data['_loginTime'])){
                    echo json('Token验证失败',401);die;
                }
                // 这里可以先进行过期验证(此处省略)
                $user=$data;
                //$user=model('member')->read(['id'=>$data['id']]);
            }
        }
        if(empty($user)){
            echo json(lang('Please log in first'),401);die;
        }
        $this->user=$user;
    }
}